package com.web.page;

import com.web.annotations.Copy;
import com.web.annotations.PageElement;
import com.web.imp.AbstractWebPage;
import com.web.model.element.WebButton;
import com.web.model.element.WebTextField;

public class RecoverPassword extends AbstractWebPage{

	public static final String EMAIL_LINK_URL = "/user/forgotstep3/key/";

	public static final String INDEX_URL_AFTER_RECOVER = "https://my.int.zyncro.com/";
	
	@Copy(id = "title_login")
	public static String TITLE_COPY;
	
	
	@PageElement(id = "user")
	private WebTextField emailField;
		
	@PageElement(id = "password1")
	private WebTextField passwordField;
	
	@PageElement(id = "password2")
	private WebTextField confirmPasswordField;
	
	@PageElement(id = "add_login")
	private WebButton sendButton;
		
	private static String finalUrl;
	
	public String getUrl(){
		
		if(finalUrl != null){
			return finalUrl;
		
		}else
			throw new IllegalStateException("Recover password url is null");
	}
	
	public static String getTitle(){
		
		return TITLE_COPY + " - " + Index.TITLE;
	}
	
	public static void setUrl(String newUrl){
		
		if(finalUrl == null){
			
			finalUrl = newUrl;
		}
		else
			throw new IllegalStateException("Url has already been set");
	}
	
	public String getUserFieldValue(){
		
		return emailField.getValue();
	}
	
	public Index setNewPassword(String password){
		
		passwordField.sendKeys(password);
		confirmPasswordField.sendKeys(password);
		
		sendButton.click();
		
		return browser.goTo(Index.class);
	}
}
